import 'package:compass/route/tab_bar.dart';
import 'package:flutter/material.dart';

import 'style/theme.dart';

class App extends StatefulWidget {
  const App({super.key});

  final title = '罗盘';

  final restorationId = 'compass';

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  int _currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    final colorScheme = Theme.of(context).colorScheme;
    final textTheme = Theme.of(context).textTheme;

    return MaterialApp(
      title: widget.title,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: compassGolden),
        useMaterial3: true,
      ),
      home: Scaffold(
          body: IndexedStack(
            index: _currentIndex,
            children: tabBar.map((e) => e.children).toList(),
          ),
          bottomNavigationBar: BottomNavigationBar(
            items: tabBar.map((e) => e.tabBarItem).toList(),
            showUnselectedLabels: true,
            currentIndex: _currentIndex,
            type: BottomNavigationBarType.fixed,
            onTap: (index) {
              setState(() {
                _currentIndex = index;
              });
            },
            selectedFontSize: textTheme.bodySmall!.fontSize!,
            unselectedFontSize: textTheme.bodySmall!.fontSize!,
            selectedItemColor: colorScheme.onPrimary,
            unselectedItemColor: colorScheme.onPrimary.withOpacity(0.7),
            backgroundColor: compassGolden,
          )),
    );
  }
}
